package cn.tedu._05weibo.controller;


import cn.tedu._05weibo.base.response.JsonResult;
import cn.tedu._05weibo.base.response.StatusCode;
import cn.tedu._05weibo.mapper.CommentMapper;
import cn.tedu._05weibo.pojo.dto.CommentDto;
import cn.tedu._05weibo.pojo.vo.CommentVO;
import cn.tedu._05weibo.pojo.vo.UserVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("v1/comment/")
@Api(tags = "03.评论模块")
public class CommentController {
    @Autowired(required = false)
    private CommentMapper commentMapper;


    //评论接口
    @ApiOperation(value = "评论功能")
    @PostMapping("insert")
    public JsonResult insertComment(@RequestBody CommentDto commentDto, @ApiIgnore HttpSession session){
        UserVO userVO=(UserVO) session.getAttribute("user");
        if (userVO==null)
            return new JsonResult(StatusCode.NOT_LOGIN);
        commentDto.setUserId(userVO.getId());
        commentMapper.insertComment(commentDto);
        return new JsonResult(StatusCode.OPERATION_SUCCESS);
    }


    //获取微博评论接口
    @ApiOperation(value = "获取微博所有评论功能")
    @GetMapping("selectByWeiboId")
    public JsonResult selectCommentByWeiboId(Long id){
        return new JsonResult(StatusCode.OPERATION_SUCCESS,commentMapper.selectCommentByWeiboId(id));
    }



}
